package cn.psh.basic.service.impl;

import cn.psh.basic.service.IBaiduAiAuditService;
import cn.psh.basic.util.BaiduAuditUtils;
import cn.psh.pet.mapper.PetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BaiduAiAuditServiceImpl implements IBaiduAiAuditService {

    @Autowired
    private PetMapper petMapper;


    @Override
    public Boolean textAudit(String auditText) {

        //判断是否穿空
        if (auditText != null) {
            Boolean textBoolean = BaiduAuditUtils.TextCensor(auditText);
            //调用工具类判断是否存在违规
            if (textBoolean) {
                return true;
            } else {
                return false;
            }
        } else {
            //为空则直接返回false
            return false;
        }

    }

    /*
     *  注意:resources是这样的格式：
     *  /group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk161.png,/group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk162.png
     *  需要判断是否为空，只有一张怎么处理，有多张怎么处理
     *  需要统一加前缀：http://123.207.27.208
     */
    @Override
    public boolean imageAudit(String resources) {
        String Httpprefix = "http://123.207.27.208";
        if (resources != null) {
            String[] split = resources.split(",");
            for (String url : split) {
                Boolean aBoolean = BaiduAuditUtils.ImgCensor(Httpprefix + url);
                if (aBoolean == true) {
                    return true;
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}